import { NextRequest, NextResponse } from 'next/server';
import { query } from '@/lib/sqlite_db';

export async function GET() {
  try {
    const usages = await query(
      'SELECT id, request_type, prompt_tokens, completion_tokens, total_tokens, created_at FROM logs ORDER BY created_at DESC LIMIT 10'
    );

    return NextResponse.json({ data: usages });
  } catch (error) {
    console.error('获取Token使用记录失败:', error);
    return NextResponse.json({ data: [], error: '获取记录失败' }, { status: 500 });
  }
}